package net.coolskill.demo.springboot.config;

import net.coolskill.demo.springboot.aop.ProfilerAdvisingBeanPostProcessor;
import net.coolskill.demo.springboot.filter.DumpFilterCondition;
import net.coolskill.demo.springboot.filter.RequestContextFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WebFilterConfig {

    @Bean
    @Conditional(DumpFilterCondition.class)
    public FilterRegistrationBean<RequestContextFilter> createRequestContextFilter() {
        FilterRegistrationBean<RequestContextFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new RequestContextFilter());
        registration.addUrlPatterns("/api/*");
        registration.setName("userRequestContextFilter");
        //registration.setOrder(1);
        registration.addInitParameter("t", "ss");
        return registration;
    }

    @Bean
    public ProfilerAdvisingBeanPostProcessor getMyAnnotationBeanPostProcessor() {
        return new ProfilerAdvisingBeanPostProcessor();
    }
}
